<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
		<meta charset="utf-8">
   		<meta http-equiv="X-UA-Compatible" content="IE=edge">
    	<meta name="viewport" content="width=device-width, initial-scale=1">
		<title>注册-M-SS</title>
		<!-- Bootstrap -->
    	<link href="css/bootstrap.min.css" rel="stylesheet">
    	<link rel="stylesheet" href="css/sticky-footer-navbar.css" />
    	<link rel="stylesheet" href="css/login.css" />
    	<link rel="stylesheet" href="css/index.css" />
    	<link rel="stylesheet" href="css/normalize.css">
    	<link rel="stylesheet" href="css/style1.css" media="screen" type="text/css" />
    	<script src="js/jquery.min.js"></script>
    	<style>
html, body { background: #000; margin: 0; padding:0;}
canvas { width: 100%; height: 100%; position: absolute; }


</style>
    	

  </head>
  
	<body>
	<canvas></canvas>
<script>
$(function(){
  var canvas = document.querySelector('canvas'),
      ctx = canvas.getContext('2d')
  canvas.width = window.innerWidth;
  canvas.height = window.innerHeight;
  ctx.lineWidth = .3;
  ctx.strokeStyle = (new Color(150)).style;

  var mousePosition = {
    x: 30 * canvas.width / 100,
    y: 30 * canvas.height / 100
  };

  var dots = {
    nb: 750,
    distance: 50,
    d_radius: 100,
    array: []
  };

  function colorValue(min) {
    return Math.floor(Math.random() * 255 + min);
  }
  
  function createColorStyle(r,g,b) {
    return 'rgba(' + r + ',' + g + ',' + b + ', 0.8)';
  }
  
  function mixComponents(comp1, weight1, comp2, weight2) {
    return (comp1 * weight1 + comp2 * weight2) / (weight1 + weight2);
  }
  
  function averageColorStyles(dot1, dot2) {
    var color1 = dot1.color,
        color2 = dot2.color;
    
    var r = mixComponents(color1.r, dot1.radius, color2.r, dot2.radius),
        g = mixComponents(color1.g, dot1.radius, color2.g, dot2.radius),
        b = mixComponents(color1.b, dot1.radius, color2.b, dot2.radius);
    return createColorStyle(Math.floor(r), Math.floor(g), Math.floor(b));
  }
  
  function Color(min) {
    min = min || 0;
    this.r = colorValue(min);
    this.g = colorValue(min);
    this.b = colorValue(min);
    this.style = createColorStyle(this.r, this.g, this.b);
  }

  function Dot(){
    this.x = Math.random() * canvas.width;
    this.y = Math.random() * canvas.height;

    this.vx = -.5 + Math.random();
    this.vy = -.5 + Math.random();

    this.radius = Math.random() * 2;

    this.color = new Color();
    console.log(this);
  }

  Dot.prototype = {
    draw: function(){
      ctx.beginPath();
      ctx.fillStyle = this.color.style;
      ctx.arc(this.x, this.y, this.radius, 0, Math.PI * 2, false);
      ctx.fill();
    }
  };

  function createDots(){
    for(i = 0; i < dots.nb; i++){
      dots.array.push(new Dot());
    }
  }

  function moveDots() {
    for(i = 0; i < dots.nb; i++){

      var dot = dots.array[i];

      if(dot.y < 0 || dot.y > canvas.height){
        dot.vx = dot.vx;
        dot.vy = - dot.vy;
      }
      else if(dot.x < 0 || dot.x > canvas.width){
        dot.vx = - dot.vx;
        dot.vy = dot.vy;
      }
      dot.x += dot.vx;
      dot.y += dot.vy;
    }
  }

  function connectDots() {
    for(i = 0; i < dots.nb; i++){
      for(j = 0; j < dots.nb; j++){
        i_dot = dots.array[i];
        j_dot = dots.array[j];

        if((i_dot.x - j_dot.x) < dots.distance && (i_dot.y - j_dot.y) < dots.distance && (i_dot.x - j_dot.x) > - dots.distance && (i_dot.y - j_dot.y) > - dots.distance){
          if((i_dot.x - mousePosition.x) < dots.d_radius && (i_dot.y - mousePosition.y) < dots.d_radius && (i_dot.x - mousePosition.x) > - dots.d_radius && (i_dot.y - mousePosition.y) > - dots.d_radius){
            ctx.beginPath();
            ctx.strokeStyle = averageColorStyles(i_dot, j_dot);
            ctx.moveTo(i_dot.x, i_dot.y);
            ctx.lineTo(j_dot.x, j_dot.y);
            ctx.stroke();
            ctx.closePath();
          }
        }
      }
    }
  }

  function drawDots() {
    for(i = 0; i < dots.nb; i++){
      var dot = dots.array[i];
      dot.draw();
    }
  }

  function animateDots() {
    ctx.clearRect(0, 0, canvas.width, canvas.height);
    moveDots();
    connectDots();
    drawDots();

    requestAnimationFrame(animateDots);	
  }

  $('canvas').on('mousemove', function(e){
    mousePosition.x = e.pageX;
    mousePosition.y = e.pageY;
  });

  $('canvas').on('mouseleave', function(e){
    mousePosition.x = canvas.width / 2;
    mousePosition.y = canvas.height / 2;
  });

  createDots();
  requestAnimationFrame(animateDots);	
});
</script>
	
		<!--导航-->
		<nav class="navbar navbar-inverse  navbar-fixed-top" id="nav1">
			<div class="container" id="nav_1">
				<nav class="navbar-header">
					<button class="navbar-toggle collapsed" data-toggle="collapse" data-target="#myNavbar">
						<span class="icon-bar"></span>
						<span class="icon-bar"></span>
						<span class="icon-bar"></span>
					</button>
					<a href="${pageContext.request.contextPath }/index.jsp" class="navbar-brand">M-SS网上商城</a>
				</nav>
				<div class="collapse navbar-collapse" id="myNavbar" id="myNavbar">
					<ul class="nav navbar-nav">
						<li><a href="${pageContext.request.contextPath }/index.jsp">首页</a></li>
						<li class="active"><a href="#">注册</a></li>
						<li><a href="#">功能2</a></li>
						<li><a href="#">功能3</a></li>
						<li><a href="#">功能4</a></li>
					</ul>
					<ul class="nav navbar-nav navbar-responsive-collapse navbar-right">
						<li>
							<a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-user"></span> <c:if test="${MyUser eq null }">我的账户</c:if><c:if test="${MyUser ne null }">${MyUser.username }</c:if> <span class="caret"></span></a>
							<c:if test="${MyUser eq null }">
								<ul class="dropdown-menu dropdown-menu-left">
						        	<li><a href="${pageContext.request.contextPath }/login.jsp">登录</a></li>
						        	<li><a href="${pageContext.request.contextPath }/register.jsp">注册</a></li>   
					          	</ul>
				          	</c:if>
				          	<c:if test="${MyUser ne null }">
					          	<ul class="dropdown-menu dropdown-menu-left">
						        	<li><a href="${pageContext.request.contextPath }/user/userinfo.jsp">我的信息</a></li>
						        	<li><a href="${pageContext.request.contextPath }/user/order.jsp">我的订单</a></li>   
						        	<li><a href="${pageContext.request.contextPath }/exitServlet">退出</a></li>   
					          	</ul>
			          		</c:if>
						</li>
						<li>
							<a href="#"><span class="glyphicon glyphicon-shopping-cart"></span> 购物车</a>
						</li>
					</ul>
					<form class="navbar-form navbar-right hidden-sm">
						<div class="form-group">
							<input class="form-control" type="text" placeholder="搜索商品" id="serch" />
						</div>
						 <button type="submit" class="btn btn-success">搜索</button>
					</form>
		     	</div>
			</div>
		</nav>
		<!--导航-->
		
		<div class="container" id="login">
			<div class="container" >
				<h3><span class="glyphicon glyphicon-fire" id="dao1"></span>&nbsp;&nbsp;&nbsp;<br><br><br><br> </h3>
			</div>
	      		<form action="/M-SS/registerServlet" class="form-group" method="post" id="register">
	      			<!--用户名-->
	      			<div class="input-group col-sm-4 col-sm-offset-4" id="chang">
	      				<span class="input-group-addon"><span class="glyphicon glyphicon-user"></span></span>
	      				<input class="form-control" type="text" placeholder="用户名由4-12位字母、数字、下划线组成" name="username" id="username"/> <!--...............-->
	      			</div>
	      			<!--用户名-->
	      			<br />
	      			<!--密码-->
	      			<div class="input-group col-sm-4 col-sm-offset-4" id="chang">
	      				<span class="input-group-addon"><span class="glyphicon glyphicon glyphicon-lock"></span></span>
	      				<input class="form-control" type="password" placeholder="密码由长度为6-20的字符组成" name="password" id="password"/>  <!--...............-->
	      			</div>
	      			<!--密码-->
	      			<br />
	      			<!--提交登录-->
	      			<div class="input-group col-sm-4 col-sm-offset-4 col-xs-12">
	      				<input type="submit" value="注册" class="btn btn-lg btn-success btn-group-justified btbk"  id="reg_btn"/>  <!--...............-->
	      			</div>
	      			<!--提交登录-->
	      		</form>
   		</div>
		
		<footer class="container-fluid panel-footer text-center footer">
			<p>网上商城 Copyright</p>
		</footer>

    <script src="js/jquery.min.js"></script>
  
    <script src="js/bootstrap.min.js"></script>
    <script type="text/javascript">
    	var  reg_form = document.forms["register"];  //获取form表单，也可以通过id获取
    	var  uname = reg_form.elements["username"];   //用户名
    	var  pwd1 = reg_form.elements["password"];   //密码1
    	var  reg_btn = reg_form.elements["reg_btn"]; //按钮
    	
    	
    	var  zz_uname = /^\w{4,12}$/;   //用户名由4-12位字母、数字、下划线组成
    	var  zz_pwd = /^\S{6,20}$/;   //密码由长度为6-20的字符组成。也就是 6-20个【非空格】字符
    	
    	reg_btn.onclick = function(){
    		
    	    if(  !zz_uname.test(uname.value) ){ //用户名验证没通过 ，等同于：zz_uname.test(uname.value)==false
    			alert("用户名格式不正确，请重新输入！");
    			uname.focus(); //用户名聚焦。让用户准备输入。
    			return false; // 阻止表单提交
    		}
    		if( !zz_pwd.test(pwd1.value) ){ //密码验证
    			alert("密码错误，请重新输入！");
    			pwd1.focus(); //密码1聚焦。让用户准备输入。
    			return false; // 阻止表单提交
    		}
    	}
    	
    	</script>
	</body>
</html>
